"""
给定若干个物品，问背包中能留下的最小空间
Dij为到第i件物品体积为j的可能性
D[i][j] = D[i - 1][j] | D[i][j - Cost[i]]
为1表示可行，为0表示不行
"""
V = int(input())
N = int(input())
A = [0 for i in range(N + 1)]
for i in range(N):
    A[i + 1] = int(input())
D = [[0 for j in range(V + 1)] for i in range(N + 1)]
D[0][0] = 1
for i in range(1, N + 1):
    for j in range(V + 1):
        D[i][j] = D[i - 1][j]
        if j >= A[i]: D[i][j] = D[i][j] or D[i-1][j - A[i]]
ans = 0
while D[N][V - ans] == 0:
    ans += 1
print(ans)